#include "editlabel.h"

#include <QLineEdit>

EditLabel::EditLabel(QWidget *parent) : QLabel(parent)
{
    m_editor = new QLineEdit(this);
    m_editor->setStyleSheet("background:transparent; border: 0px;");
    connect(m_editor, SIGNAL(returnPressed()), this, SLOT(onFinishEditing()));
    m_editor->setVisible(false);
}

EditLabel::~EditLabel()
{

}

void EditLabel::mouseDoubleClickEvent(QMouseEvent *e)
{
    if (!m_editor->isVisible())
        layoutEditor();
}

void EditLabel::layoutEditor()
{
    m_editor->setVisible(true);
    m_editor->setGeometry(geometry());
    m_editor->setText(text());
    setText(QString());
}

void EditLabel::onFinishEditing()
{
    setText(m_editor->text());
    m_editor->setVisible(false);
}
